/*
 *   A task scheduler that implements Monte-Carlo simulation
 *
 *   Copyright (C) 2011 Systasis Computer Systems, Inc.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   $Id: SettingsView.java 99 2011-08-21 20:13:48Z jchimene@gmail.com $
 */
package com.systasis.sked.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.gwtplatform.mvp.client.PopupViewImpl;
import com.systasis.sked.client.presenter.DurationType;
import com.systasis.sked.client.presenter.SettingsHandlers.SettingsUiHandlers;
import com.systasis.sked.client.presenter.SettingsPresenter;

@Singleton
public class SettingsView extends PopupViewImpl implements SettingsPresenter.MyView {

    @UiTemplate("Settings.ui.xml")
    public interface SettingsViewUiBinder extends UiBinder<PopupPanel, SettingsView> {
    }

    final private PopupPanel settingsPanel;

    private SettingsUiHandlers uiHandlers;

    @UiField
    Button closeButton;

    @Inject
    public SettingsView(final EventBus eventBus, final SettingsViewUiBinder settingsViewUiBinder) {
	super(eventBus);
	settingsPanel = settingsViewUiBinder.createAndBindUi(this);
    }

    @Override
    public Widget asWidget() {
	return settingsPanel;
    }

    @UiHandler("durationBest")
    public void durationBestValueChangeHandler(ValueChangeEvent<Boolean> e) {
	uiHandlers.setDurationType(DurationType.BEST);
    }

    @UiHandler("durationEstimate")
    public void durationEstimateValueChangeHandler(ValueChangeEvent<Boolean> e) {
	uiHandlers.setDurationType(DurationType.ESTIMATE);
    }

    @UiHandler("durationLikely")
    public void durationLikelyValueChangeHandler(ValueChangeEvent<Boolean> e) {
	uiHandlers.setDurationType(DurationType.LIKELY);
    }

    @UiHandler("durationWorst")
    public void durationWorstValueChangeHandler(ValueChangeEvent<Boolean> e) {
	uiHandlers.setDurationType(DurationType.WORST);
    }

    @Override
    public void setUiHandlers(SettingsUiHandlers uiHandlers) {
	this.uiHandlers = uiHandlers;
    }

    @Override
    public void show() {
	center();
	super.show();
    }

    @UiHandler("closeButton")
    void closeButtonClicked(ClickEvent e) {
	super.hide();
    }
}
